
var app = getApp()
Page({
  data: {
    // 顶部菜单切换
    navbar: ['全部', '待付款', "待发货", "待收货", "已完成"],//【空，0，1，2，3】    
    unpaidCount: 0,//待付款0
    unshippedCount: 0,//待发货1
    uncollectedCount: 0,//待收货2
    completeCount: 0,//已完成3
    // 默认选中菜单
    currentTab: 0,
    index: 0,
    pick_name: "",
    list:[],
  },

  // 初始化加载
  onShow: function () {
    var that = this;
    that.listdata()
  },
  //查询数据 
  listdata: function () {
    var that = this;
    wx.request({
      url: app.globalData.the_host + `/order/list?tenant=t1`,
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {  
        var data = res.data;
        var a=0;
        var b = 0;
        var c = 0;
        for (var i = data.length - 1; i >= 0; i--) {
          if (data[i].expressStatus==0) {
            a = a+1;
          } else if (data[i].expressStatus == 1){
            b = b + 1;
          } else if (data[i].expressStatus == 2) {
            c = c + 1;
          } 
        }
        console.log(a,b,c)
        that.setData({
          list: res.data,
          unpaidCount : a,
          unshippedCount: b,
          uncollectedCount: c,
        });
        console.log(that.data.unpaidCount, that.data.unshippedCount, that.data.uncollectedCount, that.data.completeCount)
        wx.hideToast();//隐藏提示框
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  //顶部tab切换
  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
  },
  /* 修改 */
  upOrder: function (e) {
    let obj = JSON.stringify(e.currentTarget.dataset.data)
    wx.navigateTo({
      url: '../uporder/index?obj=' + obj
    })
  }


})
